
package com.xiaoma.myaudience.biz.task;

import java.util.ArrayList;

import android.content.Context;
import android.os.Bundle;

import com.xiaoma.myaudience.biz.model.HeadlineVideoInfo;
import com.xiaoma.myaudience.biz.model.HotVideoInfo;
import com.xiaoma.myaudience.util.Logger;
import com.xiaoma.myaudience.util.Pair;
import com.xiaoma.myaudience.util.task.BaseDataAsyncTask.DataAsyncCallback;
/**
 * 首页task
 * @author jpren
 *
 */
public class FirstPageInfoTask implements DataAsyncCallback {
    private static final String TAG = "FirstPageInfoTask";

    private Context mContext;

    private DataAsyncCallback mCallback;

    private HeadlineInfoTask mHeadlineInfoTask;

    private Bundle mBundle;

    public FirstPageInfoTask(Context context, DataAsyncCallback callback) {
        mContext = context;
        mCallback = callback;
    }

    public void execute() {
        cancel();
        mHeadlineInfoTask = new HeadlineInfoTask(mContext, DataAsyncTask.TASK_HEADLINE_INFO, this);
        mHeadlineInfoTask.execute();
    }

    public void cancel() {
        mBundle = new Bundle();
        if (mHeadlineInfoTask != null) {
            mHeadlineInfoTask.cancel(true, true);
        }
        mHeadlineInfoTask = null;
    }

    @Override
    public void onCancelled(int what) {
    }

    @Override
    public void onPostExecute(int what, Object o) {
        switch (what) {
            case DataAsyncTask.TASK_HEADLINE_INFO:
                Logger.d(TAG, " load headline over");
                mBundle.putString(HeadlineInfoTask.HEADLINES, (String)o);
                break;

            case DataAsyncTask.TASK_HOT_INFO:
                Pair<String, ArrayList<HotVideoInfo>> pair = (Pair<String, ArrayList<HotVideoInfo>>) o;
                Logger.d(TAG, " load hot over " + pair.first);
                mBundle.putParcelableArrayList(pair.first, pair.second);
                if (HotInfoTask.HOT_FILM.equals(pair.first)) {
                } else {
                }
                break;
        }
        
        if (mCallback != null) {
            mCallback.onPostExecute(DataAsyncTask.TASK_FIRST_PAGE_INFO, mBundle);
        }
    }

    @Override
    public void onPreExecute(int what) {
    	
    }

    @Override
    public void onProgressUpdate(int what, Object o) {
    }
}
